
package com.flashextended.apps.logomaker
{
	import com.flashextended.apps.logomaker.io.IOMediator;
	import com.flashextended.apps.logomaker.singleton.AppControl;
	import com.flashextended.apps.logomaker.singleton.AppLocales;
	import com.flashextended.apps.logomaker.singleton.Fonts;
	import com.flashextended.apps.logomaker.view.bottom.Bottom;
	import com.flashextended.apps.logomaker.view.core.Core;
	import com.flashextended.apps.logomaker.view.header.Header;
	import com.flashextended.apps.logomaker.view.menu.Menu;
	import com.flashextended.apps.logomaker.view.windows.properties.GenericProperties;
	import com.flashextended.appsrules.ufa.IUnifiedRiaAppRule;
	import com.flashextended.appsrules.ufa.beans.TransportObject;
	import com.flashextended.utils.server.assetloader.LoadExternalAsset;
	
	import flash.display.Loader;
	
	import mx.containers.Canvas;
	import mx.events.ResizeEvent;
	import mx.managers.PopUpManager;

/**
 * Main application class
 * LogoMaker class can be added to any flex UI object
 */ 
	public class LogoMaker extends Canvas implements IUnifiedRiaAppRule
	{
		
		private var header:Header;
		private var core:Core;
		private var bottom_silver:Bottom;
		private var menu:Menu; 
		private var properties:GenericProperties;
		private var callBack:Function;
		
		/**
		 * constructor
		 */ 
		public function LogoMaker()
		{
			settings();
			this.addEventListener(ResizeEvent.RESIZE, resizeContainer);
		}
		
		/**
		 * container settings
		 */ 
		private function settings():void
		{
			this.percentWidth = 100;
			this.percentHeight = 100;
			
		}		
		
		
		/**
		 * sets the server URL )only if is a WEB application 
		 * @see AppLocales
		 */ 
		public function set serverURL(val:String):void
		{
			AppLocales.getInstance().mainDomain = val;
		}
		
		
		/**
		 * init application
		 * init application must be called before startApp
		 * callBack is used to inform the caller that the data has been loaded or not
		 */ 
		public function initApp(callBack:Function):void
		{
			IOMediator.getInstance().setImplementation();//sets the implementation for the InputOutput based of the application type (WEB/DESKTOP)
			IOMediator.getInstance().broker.getLocales(loadLogo);
			Fonts.getInstance();
		}
		
		/**
		 * DEPRECHATED (was used for server version)
		 */ 
		private function loadLogo(logoAsset:Loader=null):void
		{ 
		}
		
		/**
		 * Start the application
		 * can also be used to restart/create new project
		 */ 
		public function startApp():void
		{
			try{
				//clean the memory
				this.removeAllChildren();
				PopUpManager.removePopUp(properties);
			}catch(e:Error)
			{
				//an error has occured / removing existing components
			}
			properties = new GenericProperties(240, 180, "Properties");
			PopUpManager.addPopUp(properties, this);
			properties.move(200, 200);
			AppControl.getInstance().properties = properties;
						
			header = new Header();
			this.addChild(header);
			core = new Core();
			this.addChild(core);
			
			
			bottom_silver = new Bottom();
			this.addChild(bottom_silver);

			menu = new Menu();
			this.addChild(menu);
			
			AppControl.getInstance().logoMaker = this;
			
			resizeContainer();
			//create new folder on server
		}
		
		/**
		 * handle resize event
		 */ 
		private function resizeContainer(e:ResizeEvent=null):void
		{
			try{
				bottom.move(0, this.height-Bottom.HEIGHT);
				menu.move(this.width/2-Menu.WDT/2, this.height-(Menu.HDT));
			}catch(e:Error)
			{
			}
		}
		
		
		
		/**
		 * Interface implementation
	 	 * TransportObject class is used to transport data through multiple flex applications
	 	 * it is part of the Unified RIA tools project from www.riawebtools.com and is not used for the 
	 	 * stand alone application
		 */ 
		public function sendDATA(destination:Function, data:TransportObject):void
		{
			
		}	
		public function receiveDATA(data:TransportObject, sender:Function):void
		{
			
		}		

	}
}